<?php

namespace app\admin\controller\buddha;

use app\common\controller\AdminController;
use app\common\lib\ArrClass;
use app\common\lib\Show;
use app\common\lib\Status;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;

/**
 * @ControllerAnnotation(title="buddha_buddha")
 */
class Buddha extends AdminController
{

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\BuddhaBuddha();

        $this->assign('getStatusList', $this->model->getStatusList());

    }

    /**
     * @return array|\think\response\Json
     */
    public function getCity()
    {
        $province = $this->request->param('province', '', 'trim');
        $keywords = $this->request->param('val', '', 'trim');
        if (empty($province)) {
            $this->error("请选择城市");
        }
        if (empty($keywords)) {
            $this->error("请输入地址");
        }
        $type = sysconfig('map', 'map_type');
        $key = "map_" . $type . "_key_id";
        $sect = sysconfig("map", $key);
        try {
            $arr = ArrClass::mapAttr();
            $obj = ArrClass::initClass($type, $arr, [], true);
            $result = $obj->suggestion($keywords, $province, $sect);
        } catch (\Exception $e) {
            return Show::json_show(Status::status_error, $e->getMessage());
        }
        if ($result['code'] = Status::status_normal) {
            return Show::json_show(Status::status_normal, "获取成功", $result['data']);
        } else {
            return Show::json_show(Status::status_error, $result['msg']);
        }
    }

    public function getBuddhaByList()
    {
        //查询分类
        try {
            $lists = $this->model->getBuddhaByList();
        } catch (\Exception $e) {
            $this->error("发生错误");
        }
        return Show::json_show(Status::mini_normal,"ok",$lists);
    }
}